var check_num=0;
var check_id;
$(function(){
	$('input#product_end_date').datepicker({
	    language: "zh-CN",
	    autoclose: true,//选中之后自动隐藏日期选择框
	    format: "yyyy-mm-dd"
	}); 
	initTable();
	$("#btn_student_add").click(function() {
		$(this).attr("href","resources/html/motal/add_student.html");
	});
	toastr.options = {
			  "closeButton": true,
			  "debug": false,
			  "newestOnTop": false,
			  //"progressBar": true,
			  "positionClass": "toast-center",
			  "preventDuplicates": false,
			  "onclick": null,
			  "showDuration": "300",
			  "hideDuration": "1000",
			  "timeOut": "1500",
			  "extendedTimeOut": "1000",
			  "showEasing": "swing",
			  "hideEasing": "linear",
			  "showMethod": "fadeIn",
			  "hideMethod": "fadeOut"
			}
	
	$("#btn_student_delete").click(function(){
		$(".toast-bottom-center").css({"top":"50%"});
		toastr.warning("删除成功");
	});
	$("#btn_alert").click(function(){
		swal("恭喜", "保存成功!", "success");
	});
	$("#btn_confirm").click(function(){
		swal({
			title : "你确定吗?",
			text : "删除此条记录!",
			type : "warning",
			showCancelButton : true,
			confirmButtonText : "删除",
			cancelButtonText: "取消",
			closeOnConfirm : false,
			closeOnCancel: false
		}, function(isConfirm) {
			if(isConfirm){
				swal("恭喜", "删除成功!", "success");
			}else{
				swal("已取消", "您取消了删除操作", "error");
			}
			
		});
	});
	
});

function initTable(){
	var url = "resources/js/motal/students.json";

	$('table#student_table').bootstrapTable({
			toolbar: '#toolbar', 
	        method:'GET',
	        dataType:'json',
	       // contentType: "application/x-www-form-urlencoded",
	        cache: false,
	        striped: true,                              //是否显示行间隔色
	        sidePagination: "client",           //分页方式：client客户端分页，server服务端分页（*）
	        url:url,
	        showColumns:true,
	        pagination:true,
	        //queryParams : queryParams,
	        minimumCountColumns:1,
	        pageNumber:1,                       //初始化加载第一页，默认第一页
	        pageSize: 2,                       //每页的记录行数（*）
	        pageList: [2, 4],        //可供选择的每页的行数（*）
	        uniqueId: "id",                     //每一行的唯一标识，一般为主键列
	        showExport: true,                    
	        exportDataType: 'all',
	        columns: [{
	        	 checkbox: true
	        },
	        {
	            field : 'stu_code',
	            title : '学号',
	            align : 'center',
	            valign : 'middle',
	            sortable : true
	        }, {
	            field : 'name',
	            title : '学生姓名',
	            align : 'center',
	            valign : 'middle',
	            sortable : true
	        }, {
	            field : 'gender',
	            title : '性别',
	            align : 'center',
	            valign : 'middle',
	            sortable : true,
	            formatter:function (value, row, index) {
	                    return value=='1'?'男':"女";
	            }
	        }, {
	            field : 'grade',
	            title : '年级',
	            align : 'center',
	            valign : 'middle',
	            sortable : true
	        }, {
	            field : 'class',
	            title : '班级',
	            align : 'center',
	            valign : 'middle',
	            sortable : true
	        }
	        ],
	        onCheck: function (row) {
	        	check_id = row.id;
	        	check_num = check_num + 1;
	            return false;
	        },
	        onUncheck: function (row) {
	        	check_num = check_num - 1;
	            return false;
	        },
	    });
}